package org.streamerstudio.ui.properties;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import org.streamerstudio.model.gstreamer.registry.GstObject;

public class DescriptionPropertySection extends AbstractPropertySection {

	private DescriptionPropertyComposite descriptionComposite;
	
	public DescriptionPropertySection() {
	}

	@Override
	public void createControls(Composite parent,
			TabbedPropertySheetPage aTabbedPropertySheetPage) {
		super.createControls(parent, aTabbedPropertySheetPage);
		descriptionComposite = new DescriptionPropertyComposite(parent, SWT.NONE);
	}

	@Override
	public void refresh() {
		if (descriptionComposite != null){
			descriptionComposite.updateComposite();
		}
	}

	@Override
	public void setInput(IWorkbenchPart part, ISelection selection) {
		super.setInput(part, selection);
		if (selection instanceof IStructuredSelection){
	        Object input = ((IStructuredSelection) selection).getFirstElement();
	        if (GstObject.class.isAssignableFrom(input.getClass())){
	        	descriptionComposite.setInput((GstObject)input);
	        }
        }
	}
}
